#!/usr/bin/python
# -*- coding: UTF-8 -*-

"""Usage: nevygenerovalo_se.py orig_extension gen_extension [dir]

Checks the success of generating files.

Caution!
Everything after the 1st dot is a suffix.

$ ./program/nevygenerovalo_se.py .pdb.pdb .pdb.new pdb
1EGW
1G2F
1GD2
1KX3
1KX5
1L3L
1M5R
1N3F
1NKP
1NLW
1OWF
1S9F
1SXQ
1TEZ
1TRO
1WTE
1XO0
1YTB
1ZS4
2A07
2ASD
2D5V
2HT0
2I13
3CMY

"""
__version__ = "$Id$"

import os, sys

def main(argv):
    if not 3 <= len(argv) <=4:
        raise ValueError("Incorrect number of args, expected 3-4, got %d:\n%s" % (len(argv), argv))
    elif len(argv) == 4:
        os.chdir(argv[3])
    orig_files = set(find_files(argv[1]))
    generated_files = set(find_files(argv[2]))
    return orig_files - generated_files

def find_files(suffix, path='.'):
    for file in os.listdir(path):
        file, suf = file.split('.', 1)
        if '.' + suf == suffix:
            yield file

if __name__ == '__main__':
    for val in sorted(main(sys.argv)):
        print val
